package com.wngbms.projectreactor;

import com.wngbms.projectreactor.bean.Favorite;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Flux;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Slf4j
public class SuggestionService {

    public Flux<Favorite> getSuggestions() {
        log.info("suggestion");

        List<Favorite> favoriteIds = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            UserService.sleep(200);
            log.info("get suggestion: {}", i);
            Favorite favorite = new Favorite();
            String id = UUID.randomUUID().toString();
            favorite.setId(i + "\tsuggest \t" + id);
            favorite.setDesc("desc \t" + id);
            favoriteIds.add(favorite);
        }

        return Flux.fromIterable(favoriteIds);
    }

    public Flux<Favorite> getCachedSuggestions() {
        log.info("getCachedSuggestions");

        List<Favorite> favoriteIds = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            UserService.sleep(200);
            log.info("getCachedSuggestions: {}", i);
            Favorite favorite = new Favorite();
            String id = UUID.randomUUID().toString();
            favorite.setId(i + "\tcache suggest \t" + id);
            favorite.setDesc("desc \t" + id);
            favoriteIds.add(favorite);
        }

        return Flux.fromIterable(favoriteIds);
    }


}
